package com.idearworld.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.idearworld.model.Comment;
import com.idearworld.service.CommentService;
import static com.idearworld.utils.ControllerUtil.failedResult;
import static com.idearworld.utils.ControllerUtil.successResult;

@Controller
@RequestMapping("/comment")
public class CommentAdminCtrl {

	@Autowired
	private CommentService commentService;
	
	@RequestMapping(method=RequestMethod.POST, consumes = "application/json", produces = "application/json")
	@ResponseBody
	public Map<String,Object> addComment(@RequestBody Comment comm){
		comm.setCommentDate(new Date());
		comm.setCommentType(0);
		this.commentService.addComment(comm);
		return successResult(comm);
	}
	
	@RequestMapping(value="/list/{idearId}",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> loadComment(@PathVariable("idearId") Integer idearId, HttpSession session){
		List<Comment> list=this.commentService.loadComments(Integer.valueOf(idearId));
		return successResult(list);
	}
	
}
